<template>
  <div>
    <div class="common-form">
      <span>{{ curItem.name }}</span>
    </div>
    <el-form size="small" :model="curItem" label-width="100px">
      <!--上下边距-->
      <el-form-item label="上边距："><el-slider v-model="curItem.style.paddingTop" show-input></el-slider></el-form-item>
      <!--上下边距-->
      <el-form-item label="下边距："><el-slider v-model="curItem.style.paddingBom" show-input></el-slider></el-form-item>
      <!--左右边距-->
      <el-form-item label="左右边距："><el-slider v-model="curItem.style.paddingLR" show-input></el-slider></el-form-item>
      <!--背景颜色-->
      <el-form-item label="背景颜色：">
        <div class="d-s-c">
          <el-color-picker v-model="curItem.style.background" show-alpha></el-color-picker>
          <el-button type="button" style="margin-left: 10px;" @click.stop="$parent.onEditorResetColor(curItem.style, 'background', '#ffffff')">重置</el-button>
        </div>
      </el-form-item>
      <el-form-item label="优惠卷来源：">
        <el-radio-group v-model="curItem.params.source">
          <el-radio :label="'auto'">自动获取</el-radio>
          <el-radio :label="'choice'">手动选择</el-radio>
        </el-radio-group>
      </el-form-item>
      <!-- 领取方式 -->
      <el-form-item label="领取方式：">
        <el-radio-group v-model="curItem.params.receive">
          <el-radio :label="'all'">一键领取</el-radio>
          <el-radio :label="'one'">逐个领取</el-radio>
        </el-radio-group>
      </el-form-item>
      <!-- 自动获取 -->
      <template v-if="curItem.params.source == 'auto'">
        <!-- 显示数量 -->
        <el-form-item label="最多显示数量："><el-input v-model="curItem.params.auto.showNum" class="w-auto"></el-input></el-form-item>
      </template>
      <!-- 手动选择 -->
      <template v-if="curItem.params.source == 'choice'">
        <el-form-item label="优惠劵列表：">
          <div class="choice-coupon-list">
            <draggable v-model="curItem.data" :options = "{draggable:'.item',animation:500}">
              <transition-group class="d-s-c f-w">
                <div v-for="(product, index) in curItem.data" class="item" :key="'key_'+index" v-if="product.is_default!=true">
                  <div class="delete-box"><i class="el-icon-error" @click="$parent.onEditorDeleleData(index, selectedIndex)"></i></div>
                  <div class="item-box">
                    <div>{{product.name}}</div>
                    <div>
                      数量：
                      <el-input v-model="product.res_nums" type="number"></el-input>
                    </div>
                  </div>
                </div>
              </transition-group>
            </draggable>
          </div>
          <div>
            <el-button icon="el-icon-plus" @click.stop="$parent.openConpon(curItem.data,true)">选择优惠券</el-button>
          </div>
        </el-form-item>
      </template>
      <!--显示数量-->
      <!-- <el-form-item label="显示数量："><el-slider v-model="curItem.params.limit" :min="1" :max="5" show-input></el-slider></el-form-item> -->
    </el-form>
  </div>
</template>

<script>
import draggable from 'vuedraggable';
export default {
  components: {
    draggable
  },
  data() {
    return {};
  },
  watch(){

  },
  props: ['curItem', 'selectedIndex', 'opts'],
  created() {
    this.curItem.style.paddingTop = parseInt(this.curItem.style.paddingTop);
    this.curItem.params.limit = parseInt(this.curItem.params.limit);
  },
  methods: {}
};
</script>

<style scoped>
  .choice-coupon-list .item {
      position: relative;
      width: 100px;
      height: 110px;
      padding: 0 5px;
      border-radius: 3px;
      margin-right: 10px;
      margin-bottom: 10px;
      border: 1px solid #dddddd;
  }
  .choice-coupon-list .item .delete-box {
    position: absolute;
    width: 20px;
    height: 20px;
    top: -10px;
    right: -10px;
    font-size: 20px;
    cursor: pointer;
    color: #999999;
  }

  .choice-coupon-list .item .delete-box:hover {
    color: rgb(255, 51, 0);
  }
</style>
